package vip.huhailong.thumbnailatorstudy.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import vip.huhailong.thumbnailatorstudy.entiry.Rs;
import vip.huhailong.thumbnailatorstudy.service.IImageProcessingService;
import vip.huhailong.thumbnailatorstudy.utils.RsUtil;

@RestController
@RequestMapping("/processing")
public class ImageProcessingController {

    @Autowired
    IImageProcessingService imageProcessingService;

    @GetMapping("/generateThumbnail")
    public Rs generateThumbnailImageForDir(String dirPath, Integer widthPix, Integer heightPix, String imageType){
        imageProcessingService.generateThumbnailImageForDir(dirPath, widthPix, heightPix, imageType);
        return RsUtil.success("生成成功，请前往文件夹:"+dirPath+"查看");
    }

    @GetMapping("/rotation")
    public void rotationImage(String filePath, Integer widthPix, Integer heightPix, Double deg, HttpServletResponse response){
      imageProcessingService.rotation(filePath, deg, widthPix, heightPix, "jpg", response);
    }

    @GetMapping("/watermark")
    public void watermarkImage(String sourceImagePath, String watermarkImagePath, Integer widthPix, Integer heightPix, Integer watermarkWidthPix, Integer watermarkHeightPix, Float opacity, HttpServletResponse response){
        imageProcessingService.addWatermark(sourceImagePath, watermarkImagePath, widthPix, heightPix, watermarkWidthPix, watermarkHeightPix, opacity, response);
    }

    @GetMapping("/getImage")
    public void generateThumbnailImage(String filePath, Integer widthPix, Integer heightPix, Boolean aspect, Double opacity, HttpServletResponse response){
        imageProcessingService.getImage(filePath, widthPix, heightPix, aspect, opacity, response);
    }
}
